package com.beyondsoft.dtc.mobile.automation.util;

import java.util.Random;

/**
 * Created by Robin on 3/11/2016.
 */
public class StringUtil {

	public static boolean isEmpty(String content) {
		return content == null || content.trim().length() == 0;
	}

	public static boolean equals(String a, String b) {
		return a == b || (a != null && b != null && a.equals(b));
	}

	public static boolean equalsIgnoreCase(String a, String b) {
		return a == b || (a != null && b != null && a.equalsIgnoreCase(b));
	}

	public static String removePrefix(String source, String target) {
		if (isEmpty(source) || isEmpty(target)) {
			return source;
		}
		return source.replace(target, "");
	}

	public static String toString(Object[] a) {
		if (a == null)
			return "null";

		int iMax = a.length - 1;
		if (iMax == -1)
			return "[]";

		StringBuilder b = new StringBuilder();
		b.append('[');
		for (int i = 0;; i++) {
			b.append(String.valueOf(a[i]));
			if (i == iMax)
				return b.append(']').toString();
			b.append(" ");
		}
	}

	public static int getRandomNumber(int min, int max) {
		return new Random().nextInt(max) % (max - min + 1) + min;
	}
}
